﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ICore;

namespace TestAutofac.Controllers
{
    public class DinnerController : Controller
    {
        private ICategoryService categoryService = null;
        private IDinnerService dinnerService = null;

        public DinnerController(IDinnerService dinnerService, ICategoryService categoryService)
        {
            this.dinnerService = dinnerService;
            this.categoryService = categoryService;
        }

        //
        // GET: /Dinner/

        public ViewResult Index()
        {
            return View(dinnerService.GetAll());
        }

        //
        // GET: /Dinner/Details/5

        public ViewResult Details(long id)
        {
            Dinner dinner = dinnerService.GetById(id);
            return View(dinner);
        }

        //
        // GET: /Dinner/Create

        public ActionResult Create()
        {
            ViewBag.CategoryID = new SelectList(categoryService.GetAll(), "ID", "Name");
            return View();
        }

        //
        // POST: /Dinner/Create

        [HttpPost]
        public ActionResult Create(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinnerService.Add(dinner);
                return RedirectToAction("Index");
            }

            ViewBag.CategoryID = new SelectList(categoryService.GetAll(), "ID", "Name", dinner.CategoryID);
            return View(dinner);
        }

        //
        // GET: /Dinner/Edit/5

        public ActionResult Edit(long id)
        {
            Dinner dinner = dinnerService.GetById(id);
            return View(dinner);
        }

        //
        // POST: /Dinner/Edit/5

        [HttpPost]
        public ActionResult Edit(Dinner dinner)
        {
            if (ModelState.IsValid)
            {
                dinnerService.Save(dinner);
                return RedirectToAction("Index");
            }
            return View(dinner);
        }

        //
        // GET: /Dinner/Delete/5

        public ActionResult Delete(long id)
        {
            Dinner dinner = dinnerService.GetById(id);
            return View(dinner);
        }

        //
        // POST: /Dinner/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            dinnerService.Delete(id);
            return RedirectToAction("Index");
        }

        //
        // GET: /Dinner/Order/5

        public ActionResult Order(long id)
        {

            return View();
        }
    }
}